/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  JPushUtil.java   
 * @Package com.swift.utils   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-7-31 下午12:45:50   
 * @version V1.0     
 */
package com.swift.maintenance.utils;

import java.util.Set;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;

import com.swift.inteface.JpushInterface;

public class JPushUtil {

	Context context;
	String alias;
	JpushInterface jpushInterface;

	public JPushUtil(Context context, String alias) {
		this.context = context;
		this.alias = alias;
	}
	
	public JPushUtil(Context context, String alias,JpushInterface jpushInterface) {
		this.context = context;
		this.alias = alias;
		this.jpushInterface = jpushInterface;
	}

	/**
	 * author hym desc 设置用户与极光绑定 2016-11-28
	 * 
	 * @param context
	 * @param alias
	 * @param call
	 */
	public void setJPushAlias() {
		JPushInterface.setAliasAndTags(context, alias, null, call);
	}

	TagAliasCallback call = new TagAliasCallback() {

		@Override
		public void gotResult(int code, String arg1, Set<String> arg2) {
			switch (code) {
			case 0:
	            //设置成功，告诉后台已经设置别名成功
//				if (!TextUtils.isEmpty(alias)) {
//					jpushInterface.OnSetTagAndAliasSuccess();
//				}
				Log.d("jpush login " ," 极光登录成功");
				break;
			case 6002:
				//重试
				Log.d("jpush login " ," 极光登录失败，重试");
				setJPushAlias();
				break;

			default:
				break;
			}
		}
	};

}
